package com.lambo.ws;

import com.alibaba.dubbo.rpc.service.GenericService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;

/**
 * Hello world!
 */
public class ConsumerRunner {
    private GenericService helloWorldService;

    public void setHelloWorldService(GenericService helloWorldService) {
        this.helloWorldService = helloWorldService;
    }

    public void postConstruct() throws InterruptedException {
        System.out.println("ConsumerRunner.postConstruct :: " + helloWorldService);
        while (true) {
            try {
                String[] parameterTypes = {"java.lang.String", "java.lang.String"};
                Object[] args = {"lambo", "nihao too!"};
                Object result = helloWorldService.$invoke("sayHello", parameterTypes, args);
                System.out.println("result == " + result);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Thread.sleep(1000);
        }

    }

    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-consumer.xml");
        context.start();
        System.in.read();
    }
}
